<template>
  <div class="page"> 
      <el-tabs v-model="activeName" class="demo-tabs no-bottom-border center-tabs" >
        <el-tab-pane label="随访医生" name="first" class="sfDoctor">
         <DoctorForm></DoctorForm>
        </el-tab-pane>
        <el-tab-pane label="检查医生" name="second" class="zrDoctor">
          <ZrDoctorForm></ZrDoctorForm>
        </el-tab-pane>
      </el-tabs>


    <!--@reloadTable="handleQuery" -->
  </div>
</template>

<script lang="ts">
import http from "@/utils/request";
import { ElMessage } from "element-plus";
import DoctorForm from "@/pages/examples/doctor/components/doctorForm.vue";
import ZrDoctorForm from "@/pages/examples/doctor/components/zrdoctorForm.vue";
export default {
  components: {
    DoctorForm,
    ZrDoctorForm,
  },
  emits: ["changeDrug"],
  data() {
    return {
      activeName: "first",
      //记录条数
      total: 1,
      //每页条数
      size: 10,
      //当前页码
      page: 1,
      //选择条数
      selectionCount: 0,
      //选择数组
      multipleSelection: [],
      //全选状态
      checkedAll: false,
      dialogObj: {
        //弹窗标题
        editResidentsTitle: "",
        //弹窗是否显示
        isDialogVisible: false,
        DialogDate: {},
      },
      state: {
        dialogUploadVisible: false,
        accept: ".xlsx,.csv",
      },
      //表格数据
      tableData: [
      ],
      ruleform: {
        name: "",
      },
      formInline: {
        //姓名
        name: "",
        //证件号码
        cardNumber: "",
        //录入人
        inputPerson: "",
        //检验日期
        testDate: "",
        exaBeginTime: "",
        exaEndTime: "",
        //导入日期
        importDate: "",
        importBeginTime: "",
        importEndTime: "",
        // 质控类型
        result: "全部",
      },
    };
  
  },
  methods: {
    handleChangeDD(newValue, oldValue) {
      console.log("newValue", newValue);
      this.state.dialogUploadVisible = newValue;
      this.getList();
    },
    //文件上传成功处理
    handleSuccess(response, file, fileList) {
      // 处理上传成功的逻辑
      console.log("上传成功", response);
      this.fileList = fileList;
    },
    getTodayRange() {
      const today = new Date();
      const formatDate = (date) => {
        const y = date.getFullYear();
        const m = (date.getMonth() + 1).toString().padStart(2, "0");
        const d = date.getDate().toString().padStart(2, "0");
        return `${y}-${m}-${d}`;
      };
      const todayStr = formatDate(today);
      console.log(todayStr);

      return [todayStr, todayStr];
    },
    //获取列表
    getList() {
      const requestData = { page: this.page, size: this.size };
      for (const key in this.formInline) {
        if (this.formInline[key]) {
          requestData[key] = this.formInline[key];
        }
      }
      //@ts-ignore
      if (requestData.testDate) {
        //@ts-ignore
        requestData.exaBeginTime = requestData.testDate[0];
        //@ts-ignore
        requestData.exaEndTime = requestData.testDate[1];
        //@ts-ignore
        delete requestData.testDate;
      }
      //@ts-ignore
      if (requestData.importDate) {
        //@ts-ignore
        requestData.importBeginTime = requestData.importDate[0];
        //@ts-ignore
        requestData.importEndTime = requestData.importDate[1];

        //@ts-ignore
        delete requestData.importDate;
      }
      console.log(requestData);

      // http.post('/assist/blood/getPageList',requestData).then((res)=>{
      //   //@ts-ignore
      //   if(res.code==200){
      //     this.tableData=res.data.list;
      //     this.total=res.data.total;
      //   }
      // })
    },
    //重置搜索
    onReset(formName) {
      this.$refs[formName].resetFields();
      this.formInline.testDate = "";
      this.formInline.importDate = "";
      this.page = 1;
    },
    //打开编辑页
    openEditResidents(row) {
      this.dialogObj.editResidentsTitle = "编辑";
      this.dialogObj.isDialogVisible = true;
      this.dialogObj.DialogDate = row;
    },
    //删除随访
    delFollow(row) {
      const idList = [row.id];
      this.$confirm("是否确定删除已选择数据", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          http.post("/assist/blood/deleteList", idList).then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              this.getList();
              //@ts-ignore
              ElMessage.error(res.message);
              this.$refs.multipleTableRef!.clearSelection();
            } else {
              //@ts-ignore
              ElMessage.error(res.message);
            }
          });
        })
        .catch(() => {});
    },
    // 改变页面容量
    handleSizeChange(val: number) {
      this.size = val;
      this.getList();
    },

    // 改变页码序号
    handleCurrentChange(val: number) {
      this.page = val;
      this.getList();
    },
    checkSelectable() {
      return this.checkedAll != true;
    },
    checkedAllChange() {
      if (this.checkedAll == true) {
        this.selectionCount = this.tableData.length;
        console.log(this.selectionCount);

        this.tableData.forEach((row: any) => {
          this.$refs.multipleTableRef!.toggleRowSelection(row, true);
        });
      } else {
        this.selectionCount = 0;
        this.$refs.multipleTableRef!.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if(val.length==this.total||val.length==this.size){
        this.checkedAll = true;
        this.selectionCount=val.length;
        
      }else{
        this.checkedAll = false;
        this.selectionCount=0;
      }  
    },
    setClassName({ column }) {
      return this.checkedAll == true ? "all-disabled" : "";
    },
    //新增体检
    exportRecord() {
      http.get("/assist/initializeExcelTemplate/blood").then((res) => {
        //@ts-ignore
        if (res.code == 200) {
          //@ts-ignore
           ElMessage.success(res.message);;
        } else {
        }
      });
    },
    //导入
    importSelect() {
      this.state.dialogUploadVisible = true;
    },
    //导出
    exportSelect() {
      let idList = this.multipleSelection.map((item) => item.id);
      http.post("/assist/blood/exportToExcel", idList).then((res) => {
        //@ts-ignore
        if (res.code == 200) {
            //@ts-ignore
            ElMessage.success(res.message);
          this.multipleSelection=[];
          this.checkedAll=false;
          window.open(res.data);
        }
      });
    },
    //删除
    testSt() {
      const idList = this.multipleSelection.map((item) => item.id);
      this.$confirm("是否确定删除已选择数据", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          http.post("/assist/blood/deleteList", idList).then((res) => {
            //@ts-ignore
            if (res.code == 200) {
              this.getList();
              //@ts-ignore
              ElMessage.success(res.message);
              this.$refs.multipleTableRef!.clearSelection();
            } else {
              //@ts-ignore
              ElMessage.error(res.message);
            }
          });
        })
        .catch(() => {});
    },
  },
  computed: {},
};
</script>
<style scoped>
.page {
  padding: 10px 20px;
  width: 100%;
  box-sizing: border-box;
}
:deep(.el-tabs__nav){
  width: 100%;
  justify-content: center;
 }

 :deep( .el-tabs__nav-wrap::after){
  display: none;
 }
 :deep(.el-tabs__item){
  font-size: 20px !important;
  margin: 0 80px;
 }
#formbox {
  display: flex;
  flex-wrap: wrap;
  padding: 0 30px;
}
.upload-demo {
  width: 100%;
  border: 2px dashed #d9d9d9;
  text-align: center;
  padding: 40px 20px;
}
.mb20 {
  /* margin: 0 20px; */
}
:deep(.el-input__wrapper) {
  width: 230px;
}
:deep(.el-form-item .el-select__wrapper) {
  min-height: 32px;
  width: 252px;
}
:deep(.el-range-editor--large.el-input__wrapper) {
  height: 32px;
  width: 232px;
}
.form-button {
  display: flex;
  justify-content: start;
}
.table-container {
  display: flex;
  flex-direction: column;
}
.table-btn {
  display: flex;
  height: 50px;
  align-items: center;
  justify-content: space-around;
}
.tr {
  text-align: right;
  height: 50px;
  line-height: 50px;
}
::v-deep .all-disabled .el-checkbox__input .el-checkbox__inner {
  display: none;
}

.new-pagination {
  margin: 30px 0 10px 0 !important;
}

</style>
